﻿using System;
using System.IO;

namespace SplitCode
{
    public interface ICoder
    {
        void Prepare(ConfObj config);
        int LoadImage(string fileName);
        void Save(int pageNum);
        void Close();
    }

    public class ConfObj
    {
        public string inputFile = String.Empty;
        public OutputType outputType = OutputType.TIF;
        public decimal quality = 8;
        public string outDir = null;
        public int fromPage;
        public int toPage;
        public bool doOverwrite = false;
    }

    public class HelperMethods
    {
        public static string ModifyFileName(string file)
        {
            if (!File.Exists(file))
            {
                return file;
            }

            for (int i = 0; i < 100000; i++)
            {
                string dir = Path.GetDirectoryName(file);
                string fileWoExt = Path.GetFileNameWithoutExtension(file);
                string ext = Path.GetExtension(file);
                string newFile = Path.Combine(dir, String.Format("{0}({1}){2}", fileWoExt, i, ext));
                if (!File.Exists(newFile))
                    return newFile;
            }

            throw new Exception("Cannot figure out new file name, cannot overwrite output files.");
        }
    }
}
